package com.padbot.qm.security;

import java.io.Serializable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.padbot.qm.exception.SystemException;
import com.padbot.qm.util.Md5Encoder;

public class UserSessionBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5251058927372286144L;
	
	private static Logger logger = LoggerFactory.getLogger(UserSessionBean.class);

	public UserSessionBean() {
	}

	private String userId;
	private String userName;
	private String nickName;
	
	private UserSessionToken token;
	
	private String tokenKey;

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public UserSessionToken getToken() {
		return token;
	}

	public void setToken(UserSessionToken token) {
		this.token = token;
	}
	
	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public String getTokenKey() {
		return tokenKey;
	}

	public void setTokenKey(String tokenKey) {
		this.tokenKey = tokenKey;
	}

	public void createTokenKey(){
		StringBuilder builder = new StringBuilder();
		builder.append("userId:").append(userId)
		.append(",userName:").append(userName)
		.append(",nickName:").append(nickName)
		.append(",time:"+token.getCreateTime());
		try {
			this.tokenKey = Md5Encoder.encoding(builder.toString());
		} catch (Exception e) {
			logger.error("创建tokenKey失败", e);
			throw new SystemException(e);
		}
	}
	
}
